import request from './request'

const http = {
  /**
   * methods：请求方法
   * @param url 请求地址
   * @param params 请求参数
   */
  get(url, params) {
    const config = {
      method: 'get',
      url: url,
      timeout: 1000*60
    }
    if(params) config.params = params
    return request(config)
  },
  getLongTime(url, params) {
    const config = {
      method: 'get',
      url: url,
      timeout: 1000*60
    }
    if(params) config.params = params
    return request(config)
  },
  post(url, params) {
    // application/x-www-form-urlencoded
    // let sType = contentType?contentType:"application/json";
    const config = {
      headers:{
        'Content-Type':'application/json'
      },
      method: 'post',
      url: url,
      timeout: 30000
    }
    // config.headers['Content-Type'] = 'application/json';
    if(params) config.data = params
    return request(config)
  },
  postForm(url, params,type){
    const config = {
      headers:{
        'Content-Type':'multipart/form-data'
      },
      method:type?type:'post',
      url: url,
      timeout: 30000
    }
    // config.headers['Content-Type'] = 'application/json';
    if(params) config.data = params
    return request(config)
  },
  
  put(url, params) {
    const config = {
      method: 'put',
      url: url,
      timeout: 30000
    }
    if(params) config.data = params
    return request(config)
  },
  delete(url, params) {
    const config = {
      method: 'delete',
      url: url,
      timeout: 30000
    }
    if(params) config.params = params
    return request(config)
  }
}

export default http
